﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using DTO.Models;

namespace CIT.Controllers
{
    public class GioithieuController : Controller
    {
        //
        // GET: /Gioithieu/

        public ActionResult Index(string id)
        {
            DataRepository dr = new DataRepository();
            List<MEDIA> dsGioiThieu = dr.MediaProvider.getMediaOut("gioithieu").ToList<MEDIA>();
            if (dsGioiThieu == null || dsGioiThieu.Count == 0)
                return View("Error");

            MEDIA obj = null;
            foreach (MEDIA item in dsGioiThieu)
                if (id == null)
                {
                    if (item.IsTop == true)
                    {
                        obj = item;
                        obj.Content = HttpUtility.HtmlDecode(obj.Content);
                        break;
                    }
                }
                else
                {
                    if (item.MediaID == id)
                    {
                        obj = item;
                        obj.Content = HttpUtility.HtmlDecode(obj.Content);
                        break;
                    }
                }

            if (obj != null)
            {
                dsGioiThieu.Remove(obj);
            }
            else
            {
                if (dsGioiThieu.Count > 0)
                {
                    obj = dsGioiThieu[0];
                }
            }

            ViewData["GioiThieu"] = dsGioiThieu;
            return View(obj);
        }

    }
}
